package prg421.lectures.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

public class SimpleJdbcExample
{
	public static void main(String[] args) 
	{
		try
		{
			// Load Driver
			Class.forName("org.relique.jdbc.csv.CsvDriver");
			
			// Create Connection
			Connection conn = DriverManager.getConnection("jdbc:relique:csv:data");
			
			// Select from the row with ID = 2
			PreparedStatement stmt = conn.prepareStatement("SELECT ID,NAME FROM sample WHERE ID=?");
			stmt.setString(1, "2");
			
			// Execute the query
		    ResultSet results = stmt.executeQuery();
		    
		    // Read and Display Data
		    while(results.next())
		    {
		    	int id = results.getInt("ID");
		    	String name = results.getString("NAME");
		    	System.out.println(id + ": " + name);
		    }
		      
			// Close Connection
		    results.close();
		    stmt.close();
		    conn.close();
		}
		catch(Exception ex)
		{
			ex.printStackTrace();
		}
	}
}
